package lambda;

import java.util.Arrays;
import java.util.List;

public class lambda1 {
    public static void main(String args[]) {
        List<String> cities = Arrays.asList("Denver", "San Francisco", "Detroit", "Orlando");
        System.out.println("\n\nTo print the values using older jdk:");
        for (String str : cities) {
            System.out.print(str + "\t");
        }
        //With Lambda in JDK 8
        System.out.println("\n\nUsing Lambda code more readable and condensed:");
        cities.forEach((String str) -> System.out.print(str + "\t"));
        System.out.println("\n\nLambda using \"value\":");
        cities.forEach(value -> System.out.print(value + "\t"));
        System.out.println("\n\nLambda using more concise of :: operator:");
        cities.forEach(System.out::println);
        System.out.println();
        System.out.println("Now print using an Iterator");
        printCities(cities);
    }
    private static void printCities(Iterable values) {
        values.forEach(s -> {
            System.out.println(s);
        });
    }
}
